<template>
  <div class="order">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    
    <!-- 卡片式图 -->
    <el-card>
      <!-- 搜索框区域 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单列表 -->
      <el-table :data="orderList" stripe border style="width: 100%">
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="220">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180">
        </el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay * 1"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showBox(scope.row)"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showProgressBox(scope.row.order_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>

      <!-- 修改地址对话框 -->
      <el-dialog
        title="修改地址"
        :visible.sync="addressVisible"
        width="50%"
        @close="adddressClosed"
      >
        <el-form
          :model="addressForm"
          :rules="rules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader
              v-model="addressForm.address1"
              :options="cityList"
              :props="{ expandTrigger: 'hover' }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input
              v-model="addressForm.address2"
              autocomplete="off"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addressVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressVisible = false"
            >确 定</el-button
          >
        </div>
      </el-dialog>

      <!-- 暂时物流进度的对话框 -->
      <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
        
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityList from "./citydata.js";

export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total: 0, //总订单数量
      orderList: [],
      addressVisible: false, //控制修改地址对话框显示隐藏
      addressForm: {
        address1: [],
        address2: "",
      },
      cityList, //省市级联的所有城市列表
      progressVisible: false, //控制物流进度对话框显示隐藏
      rules: {
        address1: [
          { required: true, message: "请填写地址信息", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请填写地址信息", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    getOrderList() {
      this.axios
        .get("orders", {
          params: this.queryInfo,
        })
        .then((res) => {
          let result = res.data;
          console.log(result);
          if (result.meta.status !== 200) {
            return this.$message.console.error(result.meta.msg);
          }
          this.orderList = result.data.goods;
          this.total = result.data.total;
        });
    },
    // 分页部分的页数切换
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrderList();
    },
    //点击编辑按钮修改地址事件
    showBox(order) {
      this.addressVisible = true;
      console.log(this.cityList);
    },
    adddressClosed() {
      console.log(this.$refs.addressFormRef);
      this.$refs.addressFormRef.resetFields();
    },
    showProgressBox(id) {
      this.progressVisible = true
      console.log(id);
      // this.axios.get(`/kuaidi/${id}`).then(res=>{
      //   console.log(res);
      // })
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination {
  text-align: left;
}
.el-cascader {
  width: 100%;
}
</style>